package top.italks.demo.mapper;

import org.apache.ibatis.annotations.Mapper;
import top.italks.demo.entity.OrderEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author 王少辉
 * @description 订单
 * @date 2019/9/7 14:58
 */
@Mapper
public interface OrderMapper {
    /**
     * 创建订单
     *
     * @param orderEntity
     */
    @Insert("INSERT INTO `order` ( `orderId`, `hrId`, `amount`, `purchaseDays`, `purchaseNumber`, `status`, `createTime` ) " +
            "VALUES ( #{orderId}, #{hrId}, #{amount}, #{purchaseDays}, #{purchaseNumber}, #{status}, #{createTime})")
    void insert(OrderEntity orderEntity);

    /**
     * 确认支付成功
     *
     * @param orderId
     * @return
     */
    @Update("UPDATE `order` SET `status` = 1 WHERE `orderId` = #{orderId}")
    int confirmOrder(String orderId);

    /**
     * 查询订单状态
     *
     * @param orderId
     * @return
     */
    @Select("SELECT `status` FROM `order` WHERE `orderId` = #{orderId}")
    int checkOrderStatus(String orderId);

    /**
     * 根据订单号查询
     *
     * @param orderId
     * @return
     */
    @Select("SELECT * FROM `order` WHERE `orderId` = #{orderId}")
    OrderEntity queryByOrderId(String orderId);
}
